package com.ledtechdesign.beans.api;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.Serializable;

import org.w3c.dom.Attr;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.TypeInfo;
import org.w3c.dom.UserDataHandler;

import com.ledtechdesign.service.Utils;

public abstract class ElementDelegate<T extends Element> implements Element,
		Serializable, Externalizable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7678130709434500264L;

	protected T e;

	public ElementDelegate(T ee) {
		this.e = ee;
	}

	public Node appendChild(Node newChild) throws DOMException {

		return this.e.appendChild(newChild);
	}

	public Node cloneNode(boolean deep) {

		return this.e.cloneNode(deep);
	}

	public short compareDocumentPosition(Node other) throws DOMException {

		return this.e.compareDocumentPosition(other);
	}

	public String getAttribute(String name) {

		return this.e.getAttribute(name);
	}

	public Attr getAttributeNode(String name) {

		return this.e.getAttributeNode(name);
	}

	public Attr getAttributeNodeNS(String namespaceURI, String localName)
			throws DOMException {

		return this.e.getAttributeNodeNS(namespaceURI, localName);
	}

	public String getAttributeNS(String namespaceURI, String localName)
			throws DOMException {

		return this.e.getAttributeNS(namespaceURI, localName);
	}

	public NamedNodeMap getAttributes() {

		return this.e.getAttributes();
	}

	public String getBaseURI() {

		return this.e.getBaseURI();
	}

	public NodeList getChildNodes() {

		return this.e.getChildNodes();
	}

	public NodeList getElementsByTagName(String name) {

		return this.e.getElementsByTagName(name);
	}

	public NodeList getElementsByTagNameNS(String namespaceURI, String localName)
			throws DOMException {

		return this.e.getElementsByTagNameNS(namespaceURI, localName);
	}

	public Object getFeature(String feature, String version) {

		return this.e.getFeature(feature, version);
	}

	public Node getFirstChild() {

		return this.e.getFirstChild();
	}

	public Node getLastChild() {

		return this.e.getLastChild();
	}

	public String getLocalName() {

		return this.e.getLocalName();
	}

	public String getNamespaceURI() {

		return this.e.getNamespaceURI();
	}

	public Node getNextSibling() {

		return this.e.getNextSibling();
	}

	public String getNodeName() {

		return this.e.getNodeName();
	}

	public short getNodeType() {

		return this.e.getNodeType();
	}

	public String getNodeValue() throws DOMException {

		return this.e.getNodeValue();
	}

	public Document getOwnerDocument() {

		return this.e.getOwnerDocument();
	}

	public Node getParentNode() {

		return this.e.getParentNode();
	}

	public String getPrefix() {

		return this.e.getPrefix();
	}

	public Node getPreviousSibling() {

		return this.e.getPreviousSibling();
	}

	public TypeInfo getSchemaTypeInfo() {

		return this.e.getSchemaTypeInfo();
	}

	public String getTagName() {

		return this.e.getTagName();
	}

	public String getTextContent() throws DOMException {

		return this.e.getTextContent();
	}

	public Object getUserData(String key) {

		return this.e.getUserData(key);
	}

	public boolean hasAttribute(String name) {

		return this.e.hasAttribute(name);
	}

	public boolean hasAttributeNS(String namespaceURI, String localName)
			throws DOMException {

		return this.e.hasAttributeNS(namespaceURI, localName);
	}

	public boolean hasAttributes() {

		return this.e.hasAttributes();
	}

	public boolean hasChildNodes() {

		return this.e.hasChildNodes();
	}

	public Node insertBefore(Node newChild, Node refChild) throws DOMException {

		return this.e.insertBefore(newChild, refChild);
	}

	public boolean isDefaultNamespace(String namespaceURI) {

		return this.e.isDefaultNamespace(namespaceURI);
	}

	public boolean isEqualNode(Node arg) {

		return this.e.isEqualNode(arg);
	}

	public boolean isSameNode(Node other) {

		return this.e.isSameNode(other);
	}

	public boolean isSupported(String feature, String version) {

		return this.e.isSupported(feature, version);
	}

	public String lookupNamespaceURI(String prefix) {

		return this.e.lookupNamespaceURI(prefix);
	}

	public String lookupPrefix(String namespaceURI) {

		return this.e.lookupPrefix(namespaceURI);
	}

	public void normalize() {

		this.e.normalize();
	}

	public void print() {
		System.out.println(this.toString());
	}

	public void readExternal(ObjectInput in) throws IOException,
			ClassNotFoundException {
		((Externalizable) this.e).readExternal(in);
	}

	public void removeAttribute(String name) throws DOMException {

		this.e.removeAttribute(name);
	}

	public Attr removeAttributeNode(Attr oldAttr) throws DOMException {

		return this.e.removeAttributeNode(oldAttr);
	}

	public void removeAttributeNS(String namespaceURI, String localName)
			throws DOMException {

		this.e.removeAttributeNS(namespaceURI, localName);
	}

	public Node removeChild(Node oldChild) throws DOMException {

		return this.e.removeChild(oldChild);
	}

	public Node replaceChild(Node newChild, Node oldChild) throws DOMException {

		return this.e.replaceChild(newChild, oldChild);
	}

	public void setAttribute(String name, String value) throws DOMException {

		this.e.setAttribute(name, value);
	}

	public Attr setAttributeNode(Attr newAttr) throws DOMException {

		return this.e.setAttributeNode(newAttr);
	}

	public Attr setAttributeNodeNS(Attr newAttr) throws DOMException {

		return this.e.setAttributeNodeNS(newAttr);
	}

	public void setAttributeNS(String namespaceURI, String qualifiedName,
			String value) throws DOMException {

		this.e.setAttributeNS(namespaceURI, qualifiedName, value);
	}

	public void setIdAttribute(String name, boolean isId) throws DOMException {

		this.e.setIdAttribute(name, isId);
	}

	public void setIdAttributeNode(Attr idAttr, boolean isId)
			throws DOMException {

		this.e.setIdAttributeNode(idAttr, isId);
	}

	public void setIdAttributeNS(String namespaceURI, String localName,
			boolean isId) throws DOMException {

		this.e.setIdAttributeNS(namespaceURI, localName, isId);
	}

	public void setNodeValue(String nodeValue) throws DOMException {

		this.e.setNodeValue(nodeValue);
	}

	public void setPrefix(String prefix) throws DOMException {

		this.e.setPrefix(prefix);
	}

	public void setTextContent(String textContent) throws DOMException {

		this.e.setTextContent(textContent);
	}

	public Object setUserData(String key, Object data, UserDataHandler handler) {

		return this.e.setUserData(key, data, handler);
	}

	@Override
	public String toString() {

		try {
			return Utils.printXML(this.e);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}
	}

	public void writeExternal(ObjectOutput out) throws IOException {
		// TODO Auto-generated method stub
		((Externalizable) this.e).writeExternal(out);
	}

}
